package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.*;
import com.intelligentcar.springboot.mapper.DataPersonTestMapper;
import com.intelligentcar.springboot.mapper.FalutMapper;
import com.intelligentcar.springboot.service.DataPersonTestServer;
import com.intelligentcar.springboot.service.FalutServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class FalutServerImpl implements FalutServer {
    @Autowired
    private FalutMapper falutMapper;
    @Autowired
    private DataPersonTestMapper dataPersonTestMapper;

    @Override
    public int addFalutData() {
        Random rm = new Random();
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String time1 =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String time2=new SimpleDateFormat("HH:mm:ss").format(new Date());
        List<Carrepair> list = falutMapper.selectAllVehicle();
        List<Station> list1 = dataPersonTestMapper.selectAllStation();
        List<Falut> list2 = falutMapper.ifTodayData(time1);
        if (list2.size()>0) {
        }else{
            if (list.size()>0){
                for (int i = 0; i<list.size(); i++){
                    Falut falut = new Falut();
                    falut.setAddTime(time);
                    falut.setDate(time1);
                    falut.setTime(time2);
                    falut.setVehicleid(list.get(i).getCarnumber());
                    int k = rm.nextInt(list1.size());
                    falut.setStation(list1.get(k).getStationName());
                    falutMapper.addFalutData(falut);
                }
            }
        }
        return 1;
    }
}
